package com.chezhujie.www.service;

import com.chezhujie.www.domain.Trolepermission;
import com.chezhujie.www.persistence.TrolepermissionMapper;
import com.xy.core.page.Pagination;
import com.xy.core.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("trolepermissionService")
public class TrolepermissionService {
	@Autowired
	private TrolepermissionMapper trolepermissionMapper;

	/**
	 * 查询某个角色权限
	 * @param param
	 * @return
	 */
	public Trolepermission getTrolepermission(Map<String,Object> param) {
		return trolepermissionMapper.getTrolepermission(param);
	}
   
	/**
	 * 查询角色权限列表
	 * @return
	 */
	public Map<String,Object> getTrolepermissionList(Map<String,Object> param) {
		Map<String,Object> returnMap = new HashMap<String,Object>();
		returnMap.put("total", trolepermissionMapper.getTotalRows(param));
		returnMap.put("rows", trolepermissionMapper.getTrolepermissionList(param));
		return returnMap;
	}
   
	/**
	 * 查询角色权限列表
	 * @return
	 */
	public  Pagination getTrolepermissionList(Map<String,Object> param,int pageSize,Integer pageNo,String order,String sort) {
		Pagination p = new Pagination();
		p.setPageNo(pageNo);
		p.setPageSize(pageSize);
		p.setOrder(order);
		p.setSort(sort);
		param.putAll(p.toMap());
		int count=trolepermissionMapper.getTotalRows(param);
		List<Trolepermission> list=	trolepermissionMapper.getTrolepermissionList(param);
	
		p.setList(list);
		p.setTotalCount(count);
		return p;
		
	}
      
	/**
	 * 新增角色权限
	 * @param trolepermission
	 * @param param
	 */
	@Transactional
	public void insertTrolepermission(Trolepermission trolepermission) {
		
		if(null==trolepermission.getPermid() && !"".equals(trolepermission.getPermid())){
			 trolepermission.setPermid(UUIDUtils.getUUID());
		}
		trolepermissionMapper.insertTrolepermission(trolepermission);
	}
   
	/**
	 * 编辑角色权限
	 * @param trolepermission
	 * @param param
	 */
	@Transactional
	public void updateTrolepermission(Trolepermission trolepermission) {
		trolepermissionMapper.updateTrolepermission(trolepermission);
	}
   
	/**
	 * 删除角色权限
	 * @param param
	 */    
	@Transactional
	public void deleteTrolepermission(List<String> permidList) {
		for(String permid: permidList){
	  		Map<String,Object> param = new HashMap<String,Object>();
	  		param.put("permid", permid);
	 	   trolepermissionMapper.deleteTrolepermission(param);	  		
		}
	}
	public List<Trolepermission> getList(Map<String,Object> param){
		return trolepermissionMapper.getTrolepermissionList(param);
	}

	public List<Trolepermission> findtpermission(
			List<String> list) {
		return trolepermissionMapper.findtpermission(list);
	}

	public List<Trolepermission> findTpermissionByRoleid(String roleid) {
		return trolepermissionMapper.findTpermissionByRoleid(roleid);
	}


}